/**
 *kuwang
 * 2019年9月25日
 */
package com.yidu.privilege.Action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.yidu.privilege.Service.RoleService;
import com.yidu.privilege.Utils.BaseMessage;
import com.yidu.privilege.Utils.Pages;
import com.yidu.privilege.vo.RoleVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @author kuwang
 *
 * 2019年9月25日 上午9:25:32
 */

@Controller
@RequestMapping("/RoleAction")
public class RoleController {
	/**
	 * 角色service
	 */
	@Resource
	RoleService rolerService ;

	/**所有
	 * 查询
	 * @param vo
	 * @param pa
	 * @return
	 */
	@RequestMapping("findAll")
	@ResponseBody
	public Map<String, Object> findAll(RoleVo vo, Pages pa){
		List<RoleVo> list=rolerService.findAll(vo,pa);
		
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("code",0);
		map.put("msg","");
		map.put("count",rolerService.count(vo));
		map.put("data",list);
		
		return map;
	}

	/**
	 * 修改，删除
	 * @param vo
	 * @param shu
	 * @return
	 */
	@RequestMapping("addOrupdate")
	@ResponseBody
	public BaseMessage addOrupdate(RoleVo vo, String shu){
		rolerService.savaOrUpdate(vo, shu);
		BaseMessage b=new BaseMessage();
		b.setState(1);
		
		
		return b;
	}

	/**
	 * id查询
	 * @param roId id
	 * @return
	 */
	@RequestMapping("findbyid")
	@ResponseBody
	public RoleVo findbyid(Integer roId){
		
		return rolerService.findbyid(roId);
	}

	/**
	 * 删除
	 * @param roId id
	 * @return
	 */
	@RequestMapping("delete")
	@ResponseBody
	public BaseMessage delete(Integer roId){
		rolerService.delete(roId);
		BaseMessage b=new BaseMessage();
		b.setState(1);
		return b;
	}
	
	
	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@RequestMapping("deleteAll")
	@ResponseBody
	public BaseMessage deleteAll(String ids) {
		
		BaseMessage bm = new BaseMessage();
		bm.setState(1);
		rolerService.deleteAll(ids);
		bm.setMsg("删除成功!");
		return bm ;
	}
}
